package com.xunwulian.dubbo.service.impl;

import com.xunwulian.api.iface.MenuAPI;
import com.xunwulian.base.dao.MenuDao;
import com.xunwulian.base.entity.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.dubbo.config.annotation.Service;

import java.util.List;

/**
 * Created by yankaili on 2017/11/26.
 */
@Service
public class MenuApiImpl implements MenuAPI {

    @Autowired
    private MenuDao menuDao;

    @Override
    public void deleteMenuById(Integer menuId) {
        menuDao.deleteMenuById(menuId);
    }

    @Override
    public Menu getMenuById(Integer menuId) {
        return menuDao.getMenuById(menuId);
    }

    @Override
    public Integer findMaxId() {
        return menuDao.findMaxId();
    }

    @Override
    public List<Menu> listAllParentMenu() {
        return menuDao.listAllParentMenu();
    }

    @Override
    public List<Menu> listSubMenuByParentId(String parentId) {
        return menuDao.listSubMenuByParentId(parentId);
    }

    @Override
    public List<Menu> listAllMenu() {
        List<Menu> rl = this.listAllParentMenu();
        for (Menu menu : rl) {
            List<Menu> subList = this.listSubMenuByParentId(String.valueOf(menu.getMENU_ID()));
            menu.setSubMenu(subList);
        }
        return rl;
    }

    @Override
    public void saveMenu(Menu menu) {
        menuDao.saveMenu(menu);
    }

    @Override
    public void updateMenu(Menu menu) {
        menuDao.updateMenu(menu);
    }

    @Override
    public void editicon(Integer menuId, String menuIcon) {
        menuDao.editicon(menuId, menuIcon);
    }

    @Override
    public void editType(Integer menuId, String menuType) {
        menuDao.editType(menuId, menuType);
    }
}
